package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.pojo.Plan;
import com.itheima.service.TreatService;
import com.itheima.utils.DateUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/treat")
public class treatmentController {

    @Reference
    private TreatService treatService;

    @RequestMapping("/add")
    public Result add (@RequestBody Map map){
        try{
            treatService.add(map);
            System.out.println(map);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_PLAN_FAIL);
        }
        return new Result(true,MessageConstant.ADD_PLAN_SUCCESS);
    }

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean pageBean){
        PageResult pageResult = treatService.findPage(pageBean);
        return pageResult;
    }

    @RequestMapping("/findPlan/{fileNumber}")
    public Result findPlan (@PathVariable String fileNumber){
        try{
            Plan plan = treatService.findPlan(fileNumber);
            return new Result(true,MessageConstant.ADD_PLAN_SUCCESS,plan);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_PLAN_FAIL);
        }

    }

}
